﻿using FarmSmartSleep.Common.Domain.BeginTable;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace FarmSmartSleep.Organ.API.Application.SleepInfoCommands.SelectRecord
{
    public class EarCodeSelectHandler : IRequestHandler<EarCodeSelectCommand, ResultT<List<SleepInfor>>>
    {
        private readonly IBaseRepository<SleepInfor> sleepInfobaseRepository;

        public EarCodeSelectHandler(IBaseRepository<SleepInfor> sleepInfobaseRepository)
        {
            this.sleepInfobaseRepository = sleepInfobaseRepository;
        }
        /// <summary>
        /// 耳号下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ResultT<List<SleepInfor>>> Handle(EarCodeSelectCommand request, CancellationToken cancellationToken)
        {
            var result= new ResultT<List<SleepInfor>>() { Code=(int)CodeEnum.search};
            var list= await sleepInfobaseRepository.GetAll().ToListAsync();
            result.Item=list;
            return result;
        }
    }
}
